<template>
	<view class="content">
		<u-swiper :list="list" height="380"></u-swiper>
		<view class="p20">
			<!--门店-->
			<view class="subtitle z-flex z-flex-between z-flex-align-c">
				<view><text>门店</text></view>
				<view @click="handViewMoreShop">
					<text class="fs24 c-999" style="margin-left: auto;">更多</text>
					<u-icon name="arrow-right" color="#999999" size="20" style="position: relative;top:-4rpx;"></u-icon>
				</view>
			</view>
			<template v-if="business.length > 0">
				<template v-for="item in business">
					<view :key="item.id" @click="handViewShopInfo(item.id)" class="br12 bgc-fff p20 mb30"
						style="overflow: hidden;position: relative;">
						<view class="fs30"><text>{{item.name}}</text></view>
						<view><text class="fs26 c-666">{{item.address}}</text></view>
						<!-- <view><u-icon name="map" color="#23bbb3" size="28"></u-icon><text class="fs24 c-theme ml4">距离 4.95km</text></view> -->
						<!-- <view class="ident fs24 bg-theme c-fff"><text>距离最近</text></view> -->
					</view>
				</template>
			</template>
			<!--VIP导航图-->
			<!-- <view class="bd1 br12 t-c fs28 c-999 mt30" style="height: 150rpx;line-height: 150rpx;">
				<text>VIP直通车</text>
			</view> -->
			<u-image src="@/static/images/vip.jpg" width="100%" height="150rpx"></u-image>

			<!--掌门人工具-->
			<view v-if="false" class="subtitle mt30">
				掌门人工具
			</view>

			<view v-if="false" class="br12 z-flex bgc-fff" style="height: 140rpx;overflow: hidden;">
				<view class="bd1" style="width: 140rpx;height: 140rpx;">
					<!-- <image src="../../static/images/avatar.png" style="width: 140rpx;height: 140rpx;"></image> -->
				</view>
				<view class="p15 flex-1">
					<view class="fs28 c-333"><text>体验卡</text></view>
					<view class="fs24 c-666 mt10 u-line-2"><text>尊敬的顾客，体验卡上为您提供了多种产品的免费体验，欢迎领取后到店进行体验！</text></view>
				</view>
			</view>
			<view v-if="false" class="br12 z-flex bgc-fff mt15" style="height: 140rpx;overflow: hidden;">
				<view class="bd1" style="width: 140rpx;height: 140rpx;">
				</view>
				<view class="p15 flex-1">
					<view class="fs28 c-333"><text>贵宾自助区</text></view>
					<view class="fs24 c-666 mt10 u-line-2"><text>尊敬的顾客，体验卡上为您提供了多种产品的免费体验，欢迎领取后到店进行体验！</text></view>
				</view>
			</view>
			<view v-if="false" class="br12 z-flex bgc-fff mt15" style="height: 140rpx;overflow: hidden;">
				<view class="bd1" style="width: 140rpx;height: 140rpx;">
				</view>
				<view class="p15 flex-1">
					<view class="fs28 c-333"><text>百业联盟会员</text></view>
					<view class="fs24 c-666 mt10 u-line-2"><text>尊敬的顾客，体验卡上为您提供了多种产品的免费体验，欢迎领取后到店进行体验！</text></view>
				</view>
			</view>

			<!--百业联盟-->
			<view class="subtitle mt30">
				公司简介
			</view>

			<view class="bgc-fff mt15">
				<u-image v-for="item in imgData" :key="item" :src="`https://cqjmc.com/img/${item}.jpg`" width="100%"
					mode="widthFix" />
			</view>
		</view>
	</view>
</template>

<script>
	// 平台 经销商 商家 店小二 用户
	// 平台/配置管理（banner配置、分账配置、平台流水查询） 注册经销商 注册管理员
	// 经销商/ 管理商家 新增编辑商家 新增编辑商家产品 是否有门店管理信息
	// 商家/ 新增编辑产品 门店信息 门店推广二维码（成为店小二）
	// 用户/ 用户推广二维码
	// 2024/4/26
	// 绑定银行卡需二次点击才成功
	// 我的分享页面字段改成动态的 
	// 电脑组件的不能点击，使用文本框
	/**
	 * mapPages/running_water/index
	 * mapPages/backAdmin/store_stream/index
	 * mapPages/backAdmin/store_info/custom
	 * mapPages/backAdmin/store_info/sharing
	 * mapPages/my_sharing/index
	 */
	import {
		businessListApi,
		getOneApi
	} from '@/api/shop.js'
	import {
		bannerListApi
	} from '@/api/banner.js'
	import {
		getBusinessMemberApi
	} from '@/api/user.js'
	import {
		getQueryString
	} from '@/libs/function.js'
	export default {
		data() {
			return {
				query: {
					page: 1,
					size: 10
				},
				business: [],
				list: [],
				src: '',
				openId: uni.getStorageSync('openid'),
				userId: uni.getStorageSync('userId'),
				member: [],
				imgData: [11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 17, 12, 13, 14, 15, 16]
			}
		},
		onLoad() {
			// uni.authorize({
			// 	scope: 'scope.userLocation',
			// 	success() {
			// 		uni.getLocation({
			// 			type: 'wgs84',
			// 			success: function(res) {
			// 				// console.log('当前位置的经度：' + res.longitude);
			// 				// console.log('当前位置的纬度：' + res.latitude);
			// 			}
			// 		});
			// 	}
			// })
		},
		async onShow() {
			await this.$onLaunched
			this.getMember()
		},
		onPullDownRefresh() {
			this.getMember()
		},
		methods: {
			async getBusinessList() {
				uni.showLoading({
					title: '数据加载中...'
				})
				const {
					code,
					data
				} = await businessListApi()
				uni.hideLoading()
				uni.stopPullDownRefresh()
				if (code != 0) return
				this.business = data.list.slice(0, 1)
			},
			// 获取门店信息
			async getMember() {
				const userId = uni.getStorageSync('userId')
				if (!userId) {
					this.getBusinessList()
					this.getBannerList()
					return
				}
				const {
					code,
					data
				} = await getBusinessMemberApi({
					memberId: userId
				})
				if (code == 0) {
					this.member = data.list
					if (data.list.length == 0) {
						this.getBusinessList()
						this.getBannerList()
					} else {
						const businessId = uni.getStorageSync('businessId')
						// if(typeof businessId == 'number' && businessId == 0){
						// 	this.getBusinessList()
						// 	this.getBannerList()
						// }
						if (typeof businessId == 'number' && businessId > 0) {
							// const storeInfo = data.list.filter(it => it.businessId == businessId)
							// if (storeInfo.length == 0) return
							// 获取门店信息，展示门店图片和门店信息
							uni.showLoading({
								title: '数据加载中...'
							})
							const storeDetail = await getOneApi({
								id: Number(businessId)
							})
							uni.hideLoading()
							uni.stopPullDownRefresh()
							if (storeDetail.code != 0) return
							const {
								address,
								name,
								id,
								img
							} = storeDetail.data
							this.business = [{
								name,
								id,
								address
							}]
							this.list = img.map(it => {
								return {
									image: it
								}
							})
						} else {
							this.getBusinessList()
							this.getBannerList()
						}
					}
				} else {
					this.getBusinessList()
					this.getBannerList()
				}
			},
			async getBannerList() {
				const {
					code,
					data
				} = await bannerListApi()
				this.list = data.list.map(it => {
					it.image = it.url
					return it
				})
			},
			handViewMoreShop() {
				if (this.$isLogin()) {
					uni.$u.route({
						type: 'navigateTo',
						url: 'mapPages/store/index'
					})
				}

			},
			handViewShopInfo(id) {
				if (this.$isLogin()) {
					uni.$u.route({
						type: 'navigateTo',
						url: 'mapPages/store_details/index?id=' + id
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		.ident {
			position: absolute;
			right: 0;
			top: 0;
			width: 120rpx;
			text-align: center;
			padding: 6rpx 10rpx;
		}
	}
</style>
